//
//  ShareDetaViewController.m
//  MMLOOK
//
//  Created by dllo on 15/9/2.
//  Copyright (c) 2015年 武俊娥. All rights reserved.
//

#import "ShareDetaViewController.h"
#import "UIImageView+WebCache.h"

@interface ShareDetaViewController ()

@property (nonatomic, retain) UIScrollView *scrol;
@property (nonatomic, retain) UIImageView *sunimageView;
@property (nonatomic, retain) UILabel *lable;

@end

@implementation ShareDetaViewController

- (void)dealloc
{
    [_scrol release];
    [_sunimageView release];
    [_lable release];
    [_detaDic release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
        self.detaDic = [NSMutableDictionary dictionary];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = [_detaDic objectForKey:@"albumName"];
    self.view.backgroundColor = [UIColor whiteColor];
    [self createViews];
    [self resetFrame];
}

-(void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}

- (void)createViews
{
    self.scrol = [[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64)] autorelease];
    _scrol.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_scrol];
    
    CGFloat width = self.scrol.frame.size.width - 20;
    CGFloat height = [[_detaDic objectForKey:@"height"] floatValue] * width / [[_detaDic objectForKey:@"width"] floatValue];
    self.sunimageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, width, height)];
    [_scrol addSubview:_sunimageView];
    [_sunimageView release];
    
    self.lable = [[UILabel alloc] initWithFrame:CGRectMake(10, _sunimageView.frame.size.height + _sunimageView.frame.origin.y + 10, _sunimageView.frame.size.width - 20, 60)];
    self.lable.font = [UIFont systemFontOfSize:15];
    [_scrol addSubview:_lable];
    [_lable release];
    
    [self.sunimageView sd_setImageWithURL:[NSURL URLWithString:[_detaDic objectForKey:@"pic"]] placeholderImage:[UIImage imageNamed:@"home.jpg"]];
    self.lable.text = [_detaDic objectForKey:@"detail"];
}

- (void)resetFrame
{
    NSDictionary *lableDic = @{NSFontAttributeName:[UIFont systemFontOfSize:15]};
    CGRect lableRect = [_lable.text boundingRectWithSize:CGSizeMake(_lable.frame.size.width, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:lableDic context:nil];
    _lable.frame = CGRectMake(10, self.sunimageView.frame.size.height + _sunimageView.frame.origin.y + 10, self.scrol.frame.size.width - 20, lableRect.size.height);
    
    _scrol.contentSize = CGSizeMake(0, _lable.frame.size.height + _lable.frame.origin.y + 10);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
